package com.ccys.doctor.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ccys.common.third.aws.s3.S3Util;
import com.ccys.common.util.Kit;
import com.ccys.common.vo.ResponseResultApp;
import com.ccys.db.cache.TranslationUtil;
import com.ccys.db.cache.UserUtil;
import com.ccys.db.dto.doctor.patientHistory.DoctorPatientHistoryReadDto;
import com.ccys.db.dto.doctor.patientHistory.DoctorVerifyPackedMedicationDto;
import com.ccys.db.entity.*;
import com.ccys.db.enums.DurationEnum;
import com.ccys.db.enums.FamilyRelationEnum;
import com.ccys.db.mapper.*;
import com.ccys.db.service.BookingBasicService;
import com.ccys.db.vo.doctor.login.ProfileVo;
import com.ccys.db.vo.doctor.patientHistory.*;
import com.ccys.doctor.service.DoctorService;
import com.ccys.doctor.service.PatientHistoryService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @program: WhiteCoat
 * @description: 患者历史相关接口
 * @author: ZhangJingCan
 * @create: 2024-02-06 13:15
 **/

@Service
@Slf4j
public class PatientHistoryServiceImpl implements PatientHistoryService {

    @Resource
    private TblBookingMapper tblBookingMapper;

    @Resource
    private TblMemberMapper tblMemberMapper;

    @Resource
    private TblSpecialisationMapper specialisationMapper;

    @Resource
    private TblDoctorPatientHistoryReadMapper readMapper;

    @Resource
    private TblMemberNoteMapper memberNoteMapper;

    @Resource
    private TblFlagMemberMapper flagMemberMapper;

    @Resource
    private TblLabResultMapper labResultMapper;

    @Resource
    private TblDoctorMapper doctorMapper;

    @Autowired(required = false)
    private DoctorService doctorService;

    @Resource
    private BookingBasicService bookingBasicService;

    @Resource
    private TblBookingImageMapper bookingImageMapper;

    @Resource
    private TblBookingReferralLetterMapper referralLetterMapper;

    @Resource
    private TblBookingDeliveryAddressMapper deliveryAddressMapper;

    @Resource
    private TblBookingPrescriptionMapper prescriptionMapper;

    @Resource
    private TblProductMapper productMapper;

    @Resource
    private TblBookingUploadFilesMapper uploadFilesMapper;

    @Resource
    private TblBookingOrderPhotoMapper prescriptionPhotoMapper;


    @Override
    public ResponseResultApp<GetBloodPressureHistoryVo> getBloodPressureHistory(String memberId) {
        if (ObjectUtil.isEmpty(memberId)){
            return ResponseResultApp.error("The member_id field is required.");
        }
        Example memberExample = new Example(TblMember.class);
        memberExample.createCriteria()
                .andEqualTo("id",memberId)
                .andEqualTo("status",1)
                .andEqualTo("delFlag",0);
        TblMember member = tblMemberMapper.selectOneByExample(memberExample);
        if (ObjectUtil.isEmpty(member)){
            return ResponseResultApp.error("Member does not exist");
        }

        List<BloodPressuresVo> list = tblBookingMapper.getBloodPressureHistory(memberId);
        GetBloodPressureHistoryVo vo = new GetBloodPressureHistoryVo();
        vo.setBloodPressures(list);
        return ResponseResultApp.success(vo);
    }

    @Override
    public ResponseResultApp<DoctorPatientHistoryReadVo> handlePatientHistoryRead(DoctorPatientHistoryReadDto dto) {
        Kit.requisiteParam("member_id","history_type","action_type");
        DoctorPatientHistoryReadVo vo = new DoctorPatientHistoryReadVo();
        dto.setDoctorId(UserUtil.getCurLoginUserId());
        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy h:mm:ss a");
        Example example = new Example(TblDoctorPatientHistoryRead.class);
        example.createCriteria().andEqualTo("doctorId",dto.getDoctorId())
                .andEqualTo("memberId",dto.getMember_id())
                .andEqualTo("type",dto.getHistory_type())
                .andEqualTo("delFlag",0);
        //判断action_type，若为2则需要新增或更新read记录
        TblDoctorPatientHistoryRead condition = new TblDoctorPatientHistoryRead();
        if(dto.getAction_type()==2){
            try {
                condition.setBookingCreatedOn(sdf.parse(dto.getBooking_created_on()));
            }catch (Exception e){
                log.error("格式化时间异常",e);
            }
            if(readMapper.updateByExample(condition,example)<1){
                //新增
                condition.setDoctorId(dto.getDoctorId());
                condition.setType(dto.getHistory_type());
                condition.setMemberId(dto.getMember_id());
                readMapper.insertSelective(condition);
            }
        }

        //consult_create_on
        //查询当前医生是否包含心理科
        dto.setIsPsych(specialisationMapper.selectDoctorByIdentificationGroup(dto.getDoctorId(), "2"));
        //如果当前医生的科室包含identificationGroup 为 2(心理科),并且如果病人最近一次问诊也是心理科，则查询当前医生的问诊，否则返回非心理科最新问诊时间
        String ret = readMapper.selectReadBookingCreateOn(dto);
        //当前查询出问诊的医生
        String curDoctorId = "";
        if(StringUtils.isNotBlank(ret)){
            String[] split = ret.split(",");
            vo.setConsult_created_on(split[0]);
            curDoctorId = split[1];
        }
        vo.setConsult_active(StringUtils.isNotBlank(vo.getConsult_created_on()));

        //note_created_on
        TblMemberNote memberNote = memberNoteMapper.selectLastOneByMember(dto.getMember_id());
        if(memberNote!=null){
            vo.setNote_created_on(memberNote.getCreatedOnUtc().toString());
        }

        //flag_create_on
        TblFlagMember flagMember = flagMemberMapper.selectLastOneByMember(dto.getMember_id());
        if(flagMember!=null){
            vo.setFlag_created_on(flagMember.getCreatedOnUtc().toString());
        }

        //laboratory
        TblLabResult labResult = labResultMapper.selectLastOneByMember(dto.getMember_id(),0);
        if(labResult!=null){
            vo.setLaboratory_active(true);
            vo.setLaboratory_created_on(String.valueOf(labResult.getScreeningTime().getTime()));
        }

        //bloodPressure
        TblLabResult labResultBp = labResultMapper.selectLastOneByMember(dto.getMember_id(),1);
        if(labResultBp!=null){
            vo.setBlood_pressure_active(true);
            vo.setBlood_pressure_created_on(labResultBp.getCreatedOnUtc().toString());
        }

        //heartRate
        String hrCreateOn = labResultMapper.selectCreateOnByHeartRate(dto.getMember_id());
        if(StringUtils.isNotBlank(hrCreateOn)){
            vo.setHeart_rate_active(true);
            vo.setHeart_rate_created_on(hrCreateOn);
        }

        //查询当前医生是否与病人有read记录
        Date date;
        condition.setDoctorId(dto.getDoctorId());
        condition.setMemberId(dto.getMember_id());
        condition.setType(1);
        List<TblDoctorPatientHistoryRead> list = readMapper.select(condition);
        if(StringUtils.isNotBlank(vo.getConsult_created_on())){
            if(!dto.getDoctorId().equals(curDoctorId)&&!list.isEmpty()){
                date = new Date(Long.valueOf(vo.getConsult_created_on()));
                if(date.before(list.get(0).getBookingCreatedOn())){
                    vo.setConsult_created_on("");
                }
            }
        }

        condition.setType(2);
        list = readMapper.select(condition);
        if(StringUtils.isNotBlank(vo.getNote_created_on())){
            if(!dto.getDoctorId().equals(memberNote.getDoctorId())&&!list.isEmpty()){
                date = new Date(Long.valueOf(vo.getNote_created_on()));
                if(date.before(list.get(0).getBookingCreatedOn())){
                    vo.setNote_created_on("");
                }
            }
        }

        condition.setType(3);
        list = readMapper.select(condition);
        if(StringUtils.isNotBlank(vo.getFlag_created_on())){
            if(!dto.getDoctorId().equals(flagMember.getDoctorId())&&!list.isEmpty()){
                date = new Date(Long.valueOf(vo.getFlag_created_on()));
                if(date.before(list.get(0).getBookingCreatedOn())){
                    vo.setFlag_created_on("");
                }
            }
        }

        condition.setType(4);
        list = readMapper.select(condition);
        if(StringUtils.isNotBlank(vo.getLaboratory_created_on())){
            if(!list.isEmpty()){
                date = new Date(Long.valueOf(vo.getLaboratory_created_on()));
                if(date.before(list.get(0).getBookingCreatedOn())){
                    vo.setLaboratory_created_on("");
                }
            }
        }

        condition.setType(5);
        list = readMapper.select(condition);
        if(StringUtils.isNotBlank(vo.getBlood_pressure_created_on())){
            if(!list.isEmpty()){
                date = new Date(Long.valueOf(vo.getBlood_pressure_created_on()));
                if(date.before(list.get(0).getBookingCreatedOn())){
                    vo.setBlood_pressure_created_on("");
                }
            }
        }

        condition.setType(6);
        list = readMapper.select(condition);
        if(StringUtils.isNotBlank(vo.getHeart_rate_created_on())){
            if(!list.isEmpty()){
                date = new Date(Long.valueOf(vo.getHeart_rate_created_on()));
                if(date.before(list.get(0).getBookingCreatedOn())){
                    vo.setHeart_rate_created_on("");
                }
            }
        }

        //格式化时间
        if(StringUtils.isNotBlank(vo.getConsult_created_on())){
            vo.setConsult_created_on(sdf.format(new Date(vo.getConsult_created_on())));
        }
        if(StringUtils.isNotBlank(vo.getNote_created_on())){
            vo.setNote_created_on(sdf.format(new Date(vo.getNote_created_on())));
        }
        if(StringUtils.isNotBlank(vo.getFlag_created_on())){
            vo.setFlag_created_on(sdf.format(new Date(vo.getFlag_created_on())));
        }
        if(StringUtils.isNotBlank(vo.getLaboratory_created_on())){
            vo.setLaboratory_created_on(sdf.format(new Date(vo.getLaboratory_created_on())));
        }
        if(StringUtils.isNotBlank(vo.getBlood_pressure_created_on())){
            vo.setBlood_pressure_created_on(sdf.format(new Date(vo.getBlood_pressure_created_on())));
        }
        if(StringUtils.isNotBlank(vo.getHeart_rate_created_on())){
            vo.setHeart_rate_created_on(sdf.format(new Date(vo.getHeart_rate_created_on())));
        }
        return ResponseResultApp.success(vo);
    }

    @Override
    public ResponseResultApp getBookingInfoForApproval(String booking_id) {
        //查询当前医生是否在印尼106或者文莱37,1.0未判断是否可以approve
        TblDoctor doctor = doctorMapper.selectByPrimaryKey(UserUtil.getCurLoginUserId());
        if(!"106".equals(doctor.getCountryOfResidence())&&!"37".equals(doctor.getCountryOfResidence())){
            return ResponseResultApp.error(401,"Request require authorization.");
        }
        TblBooking booking = tblBookingMapper.selectByPrimaryKey(booking_id);
        JSONObject json = new JSONObject();
        json.put("booking_id",booking_id);
        json.put("status",booking.getStatus());
        return ResponseResultApp.success(json);
    }

    @Override
    public ResponseResultApp getBookingInfo(String bookingId) {
        //查询booking详情
        BookingInfoVo vo = tblBookingMapper.selectDoctorBookingInfo(bookingId);
        vo.setStatus(bookingBasicService.getStatusByBooking(bookingId));
        vo.setSubStatus(bookingBasicService.getSubStatusByBooking(bookingId));
        //diagnosis
        String diagnosis = vo.getDiagnosis();
        if(StringUtils.isNotBlank(diagnosis)){
            String[] split = diagnosis.split("-need split-");
            StringBuilder sb = new StringBuilder();
            String trans;
            for (String s : split) {
                 trans = TranslationUtil.getContentLastLanguage(s, vo.getCurrentLanguage());
                 sb.append(StringUtils.isNotBlank(trans)?trans:s).append("<br>");
            }
            vo.setDiagnosis(diagnosis.replaceAll("-need split-","<br>"));
            vo.setDiagnosisTrans(sb.toString());
        }
        //symptomsPhoto
        String symptomsPhotos = vo.getSymptomsPhotosStr();
        if(StringUtils.isNotBlank(symptomsPhotos)){
            String[] split = symptomsPhotos.split(",");
            JSONArray arr = new JSONArray();
            for (String s : split) {
                JSONObject json = new JSONObject();
                json.put("photo",S3Util.createPresignedGetUrl(s));
                arr.add(json);
            }
            vo.setSymptomsPhotos(arr);
        }
        //查询deliveryFeeDetail
        vo.setDeliveryFeeDetail(tblBookingMapper.selectDoctorBookingInfoDeliveryFeeList(bookingId));
        //tax
        BookingInfoVo.Tax tax = new BookingInfoVo.Tax();
        if(!"106".equals(vo.getPatientCountryOfResidence())){
            tax.setAmount(vo.getTaxRate().intValue());
            tax.setFee(vo.getGrandTotal().multiply(vo.getTaxRate()).setScale(BigDecimal.ROUND_HALF_UP,2));
            if(vo.getTaxRateType()!=null){
                if(vo.getTaxRateType()==0){
                    tax.setType("SGD");
                }else if(vo.getTaxRateType()==1){
                    tax.setType("percent");
                }
            }
            vo.setTax(tax);
        }
        //member以及child
        BookingInfoVo.Member member = tblMemberMapper.selectBookingInfoMember(vo.getMemId());
        if(!vo.getMemId().equals(vo.getPatientMemId())){
            BookingInfoVo.Child child = tblMemberMapper.selectBookingInfoChild(vo.getPatientMemId());
            child.setAge(DateUtil.ageOfNow(child.getDateOfBirth()));
            child.setRelationship(FamilyRelationEnum.getRelation(Integer.valueOf(child.getRelationship())));
            member.setChild(child);
        }
        vo.setMember(member);

        //patient
        BookingInfoVo.Patient patient = new BookingInfoVo.Patient();
        Example example = new Example(TblBookingImage.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("bookingId",bookingId);
        criteria.andEqualTo("delFlag",0);
        criteria.andEqualTo("imageType",3);
        example.setOrderByClause("created_on_utc desc");
        List<TblBookingImage> imageList = bookingImageMapper.selectByExample(example);
        if(!imageList.isEmpty()){
            JSONArray arr = new JSONArray();
            for (TblBookingImage img : imageList) {
                JSONObject json = new JSONObject();
                json.put("photo",S3Util.createPresignedGetUrl(img.getImageName()));
                arr.add(json);
            }
            patient.setSignature(arr);
        }
        patient.setMemTypeId(vo.getMemType().toString());
        switch (vo.getMemType()){
            case 1://nric_fin
                patient.setFrontIdentificationCardPhoto(S3Util.createPresignedGetUrl(vo.getFrontIdentificationPhoto()));
                patient.setBackIdentificationCardPhoto(S3Util.createPresignedGetUrl(vo.getBackIdentificationPhoto()));
                break;
            case 2://passport
                patient.setPassportPhoto(S3Util.createPresignedGetUrl(vo.getFrontIdentificationPhoto()));
                break;
            case 3://birth certificate
                patient.setBirthCertificate(S3Util.createPresignedGetUrl(vo.getFrontIdentificationPhoto()));
                break;
            case 4://driving license
                patient.setFrontDrivingLicense(S3Util.createPresignedGetUrl(vo.getFrontIdentificationPhoto()));
                patient.setBackDrivingLicense(S3Util.createPresignedGetUrl(vo.getBackIdentificationPhoto()));
                break;
            case 5://child photo
                break;

            default:
                patient.setFrontGeneralCardPhoto(S3Util.createPresignedGetUrl(vo.getFrontIdentificationPhoto()));
                patient.setBackGeneralCardPhoto(S3Util.createPresignedGetUrl(vo.getBackIdentificationPhoto()));
                break;
        }
        vo.setPatient(patient);

        //referrals
        vo.setReferrals(referralLetterMapper.selectBookingInfoReferralLetterList(bookingId));

        //delivery address
        vo.setDeliveryAddress(deliveryAddressMapper.selectBookingInfoDeliveryAddressList(bookingId));

        //pharmacy
        vo.setPharmacy(prescriptionMapper.selectBookingInfoPharmacyList(bookingId));

        //prescription以及stepdose
        Map<String,List<BookingInfoVo.Step_dose_medications>> stepMap = new HashMap<>();
        List<BookingInfoVo.Prescription> pList = new ArrayList<>();
        List<BookingInfoVo.Step_dose_medications> sList = prescriptionMapper.selectBookingInfoPrescriptionList(bookingId);
        for (BookingInfoVo.Step_dose_medications s : sList) {
            s.setName(s.getNameOnly()+" "+s.getIngredientOnly());
            s.setDurationUnitName(DurationEnum.getName(s.getDurationUnit()));
            if(StringUtils.isBlank(s.getStepDose())){
                BookingInfoVo.Prescription p = new BookingInfoVo.Prescription();
                BeanUtils.copyProperties(s,p);
                pList.add(p);
            }else{
                List<BookingInfoVo.Step_dose_medications> tempList = stepMap.get(s.getProductId());
                if(tempList==null){
                    tempList = new ArrayList<>();
                }
                tempList.add(s);
                stepMap.put(s.getProductId(),tempList);
            }
        }
        for (BookingInfoVo.Prescription p : pList) {
            if(stepMap.get(p.getProductId())!=null){
                p.setStepDoseMedications(stepMap.get(p.getProductId()));
            }
        }
        vo.setPrescription(pList);

        //symptoms
        String symptomsStr = vo.getSymptomsStr();
        if(StringUtils.isNotBlank(symptomsStr)){
            String[] split = symptomsStr.split("-need split-");
            JSONArray arr = new JSONArray();
            for (String s : split) {
                JSONObject json = new JSONObject();
                json.put("name",s);
                arr.add(json);
            }
            vo.setSymptoms(arr);
        }
        //medications
        vo.setMedications(tblBookingMapper.findMedicationsByBookingId(bookingId));
        //allergies
        vo.setAllergies(tblBookingMapper.findAllergiesByBookingId(bookingId));
        //longterms
        vo.setLongterms(tblBookingMapper.findLongtermsByBookingId(bookingId));
        //medicationreactions
        vo.setMedicationReactions(tblBookingMapper.findMedicationReactionsByBookingId(bookingId));
        //medicalservice
        vo.setMedicalService(tblBookingMapper.findMedicalServiceByBookingId(bookingId));
        //uploadFiles
        List<BookingInfoVo.UploadFiles> uploadFiles = uploadFilesMapper.selectBookingInfoUploadFileList(bookingId);
        for (BookingInfoVo.UploadFiles uploadFile : uploadFiles) {
            uploadFile.setFilePath(S3Util.createPresignedGetUrl(uploadFile.getFileName()));
        }
        vo.setUploadFiles(uploadFiles);

        //booking_cdmp_condition
        vo.setBookingCdmpCondition(tblBookingMapper.findBookingCdmpConditionByBookingId(bookingId));
        //prescriptionPhoto
        List<BookingInfoVo.PrescriptionPhotos> ppList = prescriptionPhotoMapper.selectBookingInfoPrescriptionPhotoList(bookingId);
        for (BookingInfoVo.PrescriptionPhotos p : ppList) {
            p.setCreatedOn(DateUtil.format(new Date(Long.valueOf(p.getCreatedOn())),"yyyy-MM-dd HH:mm:ss"));
        }
        vo.setPrescriptionPhotos(ppList);

        //productPackages
        vo.setProductPackages(tblBookingMapper.findProductPackagesByBookingId(bookingId));


        return ResponseResultApp.success(vo);
    }

    @Override
    public ResponseResultApp verifyPackedMedication(DoctorVerifyPackedMedicationDto dto) {
        dto.setDoctor_id(UserUtil.getCurLoginUserId());
        prescriptionMapper.updateVerifyPacked(dto);
        return ResponseResultApp.success();
    }

    @Override
    public ResponseResultApp<ProfileVo.ActiveBooking> getConsultingPatient() {
        return ResponseResultApp.success(doctorService.getActiveBooking());
    }

    @Override
    public ResponseResultApp<DoctorGetBookingDetailVo> getBookingDetail(String bookingId) {
        if (ObjectUtil.isEmpty(bookingId)){
            return ResponseResultApp.error("The booking_id field is required.");
        }
        DoctorGetBookingDetailVo vo = tblBookingMapper.doctorGetBookingDetail(bookingId);

        //cdmpCondition
        List<CdmpConditionPricingMakeVo> tempConditionList = tblBookingMapper.findCdmpConditionPricingByBookingId(vo.getPatientCountryOfResidence(), vo.getBenefitId());
        List<CdmpConditionPricingMakeVo> cdmpConditionPricingList = new ArrayList<>();
        if(!tempConditionList.isEmpty()){
            List<CdmpConditionsMakeVo> cdmpConditionList = new ArrayList<>();
            for (CdmpConditionPricingMakeVo v : tempConditionList) {
                String[] split = v.getName().split(",");
                for (String s : split) {
                    //condition
                    CdmpConditionsMakeVo v1 = new CdmpConditionsMakeVo();
                    v1.setConditionName(s);
                    v1.setPackageName(v.getPackageName());
                    v1.setCdmpProgramBenefitId(v.getCdmpProgramBenefitId());
                    v1.setCdmpProgramConditionId(v1.getCdmpProgramBenefitId()+v1.getConditionName());
                    cdmpConditionList.add(v1);

                    //pricing
                    CdmpConditionPricingMakeVo v2 = new CdmpConditionPricingMakeVo();
                    BeanUtils.copyProperties(v,v2);
                    v2.setCdmpProgramConditionId(v1.getCdmpProgramConditionId());
                    v2.setCompareKey(v2.getName());
                    v2.setPricingName(v2.getName());
                    cdmpConditionPricingList.add(v2);
                }
            }
            vo.setCdmpConditions(cdmpConditionList);
            vo.setCdmpConditionPricing(cdmpConditionPricingList);
        }

        //booking_selected_cdmp_condition


        //无数据时返回错误
        if (ObjectUtil.isNull(vo)){
            return ResponseResultApp.error("Booking invalid");
        }
        //翻译诊断
        if (ObjectUtil.isNotEmpty(vo.getDiagnosis())){
            String trans = TranslationUtil.getContentLastLanguage(vo.getDiagnosis(), tblMemberMapper.selectByPrimaryKey(vo.getMemberId()).getCurrentLanguage());
            vo.setDiagnosisTrans(StringUtils.isBlank(trans) ? vo.getDiagnosis() : trans);
        }
        //获取症状照片路径(包含临时凭证的路径)
        if (ObjectUtil.isNotEmpty(vo.getSymptomsPhotos())){
            vo.getSymptomsPhotos().forEach(item->{
                if (ObjectUtil.isNotEmpty(item.getPhoto())){
                    item.setPhoto(S3Util.createPresignedGetUrl(item.getPhoto()));
                }
            });
        }
        //给长期疾病信息做翻译
        if (ObjectUtil.isNotEmpty(vo.getLongterms())){
            vo.getLongterms().forEach(item->{
                String trans = TranslationUtil.getContentLastLanguage(item.getLongTermConditionName(), tblMemberMapper.selectByPrimaryKey(vo.getMemberId()).getCurrentLanguage());
                item.setLongTermConditionTransName(StringUtils.isBlank(trans) ? item.getLongTermConditionName() : trans);
            });
        }
        //设置上传的文件路径
        if (ObjectUtil.isNotEmpty(vo.getUploadFiles())){
            vo.getUploadFiles().forEach(item->{
                item.setFilePath(S3Util.createPresignedGetUrl(item.getFileName()));
            });
        }
        //设置转介绍信的路径
        if (ObjectUtil.isNotEmpty(vo.getSpecialistReferralLetterPhotos())){
            vo.getSpecialistReferralLetterPhotos().forEach(item->{
                item.setPhoto(S3Util.createPresignedGetUrl(item.getPhoto()));
            });
        }


//        Map<String,List<BookingInfoVo.Step_dose_medications>> stepMap = new HashMap<>();
//        List<BookingInfoVo.Prescription> pList = new ArrayList<>();
//        List<BookingInfoVo.Step_dose_medications> sList = prescriptionMapper.selectBookingInfoPrescriptionList(vo.getId());
//        for (BookingInfoVo.Step_dose_medications s : sList) {
//            s.setName(s.getNameOnly()+" "+s.getIngredientOnly());
//            s.setDurationUnitName(DurationEnum.getName(s.getDurationUnit()));
//            if(StringUtils.isBlank(s.getStepDose())){
//                BookingInfoVo.Prescription p = new BookingInfoVo.Prescription();
//                BeanUtils.copyProperties(s,p);
//                pList.add(p);
//            }else{
//                List<BookingInfoVo.Step_dose_medications> tempList = stepMap.get(s.getProductId());
//                if(tempList==null){
//                    tempList = new ArrayList<>();
//                }
//                tempList.add(s);
//                stepMap.put(s.getProductId(),tempList);
//            }
//        }
//        for (BookingInfoVo.Prescription p : pList) {
//            if(stepMap.get(p.getProductId())!=null){
//                p.setStepDoseMedications(stepMap.get(p.getProductId()));
//            }
//        }
//        vo.setPrescription(pList);


        return ResponseResultApp.success(vo);
    }


}
